package com.fancy.learncenter.activity.base;

import android.annotation.TargetApi;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.fancy.learncenter.common.StatusBarCompat;
import com.fancy.learncenter.utils.ProgressUtil;
import com.fancy.teeya.R;


/**
 * Created by Hyy on 2016/9/18.
 */
public class BaseActivity extends AppCompatActivity {
    Dialog dialog = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);
    }

    public void setContentView(int layoutResID, Status Type) {
        this.setContentView(layoutResID);
        setType(Type);
    }


    public void initToolbar(String Title) {
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        if (toolbar != null) {
            ImageView back = (ImageView) findViewById(R.id.back);
            back.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });

            TextView title = (TextView) findViewById(R.id.title);
            title.setText(Title);
        }

    }


    public void setType(Status type) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            switch (type) {
                case NAVIGATION:
                    getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
                    getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                    break;
                case STATUS:
                    getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                    break;
            }
        }
    }

    public enum Status {
        NAVIGATION, STATUS, Default
    }

    public void dialogShow() {
        if (dialog == null) {
            dialog = ProgressUtil.creatRequestDialog(this, "正在请求");
        }
        dialog.show();
    }

    public void dialogDis() {
        if (dialog != null) {
            dialog.dismiss();
        }
    }

    public static int getStatusBarHeight(Context context) {
        int result = 0;
        int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = context.getResources().getDimensionPixelSize(resourceId);
        }
        return result;
    }
}
